<template>
  <div class="container w-full h-full">
    <div class="back" @click="back">
      <img class="icon" src="static/icons/back.png" mode="" />
      <span>{{ title }}</span>
    </div>
    <div
      :class="['tabChild', active == tab.value && !isMore ? 'active_tab' : '']"
      v-for="(tab, index) in usedSubject"
      :key="index"
      @click="switchTab(tab.value)"
    >
      <span>{{ tab.label }}</span>
    </div>
    <div :class="['tabChild', 'moreOff', isMore ? 'active_tab' : '']" @click="isMore = !isMore">
      <span>更多</span>
      <img src="@/assets/homework/more@2x.png" alt="" />
    </div>
    <slot name="rightBtn"></slot>
    <!-- 更多科目 -->
    <div class="moreSubjects" v-show="isMore">
      <div style="display: flex; align-items: center">
        <div
          :class="['moreChild', active == tab.value ? 'active_moretab' : '']"
          v-for="(tab, index) in moreSubject"
          :key="index"
          @click="switchTab(tab.value)"
        >
          {{ tab.label }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title:{
      type:String,
      default:''
    },
    tabs: {
      type: Array,
      default: () => []
    },
    moreSubject: {
      type: Array,
      default: () => []
    },
    usedSubject: {
      type: Array,
      default: () => []
    },
    active: {
      type: [String, undefined],
      default: undefined
    }
  },
  data() {
    return {
      isMore: false
    }
  },
  methods: {
    switchTab(subjectId) {
      this.isMore = false
      this.$emit('change', subjectId)
    },
    back() {
      if (this.onBack) {
        this.onBack()
      } else {
        this.$router.go(-1)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  color: #fff;

  .moreSubjects {
    position: absolute;
    z-index: 999;
    bottom: -74px;
    width: 100%;
    height: 74px;
    background: #ffffff;
    box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.08);
    border-radius: 0px 0px 0px 0px;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: scroll;
    .moreChild {
      width: 140px;
      height: 46px;
      border-radius: 35px 35px 35px 35px;
      font-size: 24px;
      color: #444;
      margin: 0 16px;
      text-align: center;
      line-height: 42px;
      box-sizing: border-box;
      border: none;
      background: #f6f6f6;
      white-space: nowrap;
    }

    .active_moretab {
      color: #00a7ff;
      border: 2px solid #00a7ff;
      background: #eef9ff;
    }
  }

  .tabChild {
    width: 70px;
    font-size: 28px;
    margin: 0 28px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(100% - 10px);
    position: relative;
    span{
      white-space:nowrap;
    }
    img {
      margin-left: 5px;
      width: 13.54px;
      height: 9.06px;
    }
  }
  .moreOff {
    width: 100px;
  }
  .active_tab::after {
    content: '';
    position: absolute;
    bottom: 0px;
    width: 21px;

    height: 4px;
    background-color: #fff;
  }

  .back {
    position: absolute;
    top: 0;
    left: 20px;
    z-index: 999;
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 28px;

    .icon {
      width: 17.14px;
      height: 30px;
      margin-right: 11px;
    }
  }

  .tabs {
    border-radius: 35px;
    overflow-x: scroll;
    overflow-y: hidden;
    white-space: nowrap;

    .item {
      width: 200px;
      // font-size: 20px;
      border-radius: 35px;

      .name {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
    }
  }
}
</style>
